package com.yang.auth.controller;


import com.yang.auth.model.vo.user.UserLoginReqVo;
import com.yang.auth.service.IUserService;
import com.yang.framework.aop.log.ApiOperationLog;
import com.yang.framework.common.response.R;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户模块
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private IUserService userService;

    @PostMapping("/login")
    @ApiOperationLog("用户登录/注册")
    public R loginAndRegister(@RequestBody @Validated UserLoginReqVo userLoginReqVo) {
        String token = userService.loginAndRegister(userLoginReqVo);
        return R.success(token);
    }

    @PostMapping("/logout")
    @ApiOperationLog("退出登录")
    public R logout() {
        //  todo: 退出登录
        userService.logout();
        return R.success();
    }



}
